#

| Chapter 16 Where Did I Put That? |

## 16.7 ls Shortcuts: ll, lf, lg, etc.

The old 4.1BSD UNIX system I worked on in the early 1980s had commands named ll, for ls -l; lf, for ls -F; and lm, for the (defunct, on BSD at least... RIP) ls -m command. [For those of us who don't remember it, ls -m listed files separated by commas, rather than spaces. -ML ] When they left my system, I made my own shell script to do the same things. If your system doesn't have these, you can install the script from the CD-ROM.

This is the single script file for all the commands:

>     #! /bin/sh
>     case $0 in
>     *lf)  exec ls -F "$@";;
>     *lg)  exec ls -lg "$@";;
>     *ll)  exec ls -l "$@";;
>     *lm)  ls "$@" |
>           awk '{
>             if ((length($0) + 2 + length(inline)) > 79) {
>                 print inline ","
>                 inline = $0
>             }
>             else if (length(inline) != 0)
>                 inline = inline ", " $0
>             else # this is the first filename
>                 inline = $0
>           }
>           END {
>             print inline
>           }'
>           ;;
>     *lr)  exec ls -lR "$@";;
>     *)    echo "$0: Help!  Shouldn't get here!" 1>&2; exit 1;;
>     esac

The exec (45.7) command saves a process - this was important on my overloaded VAX 11/750, and doesn't hurt on faster systems.

You can install this script from the CD-ROM or just type it in. If you type it into a file named lf, don't forget to make the four other links (18.5): lg, ll, lm, and lr. The script tests the name it was called with, in `$0`, to decide which ls command to run. This trick saves disk space.

System V still has the -m option, so you can replace the `*lm)` section with plain `ls -m`. Also, on some UNIXes, the ls -g option does nothing; replace that section with `ls -lG` or `ls -lo`. You can add other commands, too, by adding a line to the case and another link. (For more on shell programming, start with article 44.1.)

- JP

16.6 clf, cls: "Compressed" ls Listings |  | 16.8 The ls -d Option